package com.gitee.melin.bee.util;

/**
 * This helper class is used to place some JVM runtime options(eg: `--add-opens`)
 * required by Spark when using Java 17. `DEFAULT_MODULE_OPTIONS` has added
 * `-XX:+IgnoreUnrecognizedVMOptions` to be robust.
 */
public class JavaModuleOptions {
    private static final String[] DEFAULT_MODULE_OPTIONS = {
        "-XX:+IgnoreUnrecognizedVMOptions",
        "--add-modules=jdk.incubator.vector",
        "--add-opens=java.base/java.lang=ALL-UNNAMED",
        "--add-opens=java.base/java.lang.invoke=ALL-UNNAMED",
        "--add-opens=java.base/java.lang.reflect=ALL-UNNAMED",
        "--add-opens=java.base/java.io=ALL-UNNAMED",
        "--add-opens=java.base/java.net=ALL-UNNAMED",
        "--add-opens=java.base/java.nio=ALL-UNNAMED",
        "--add-opens=java.base/java.util=ALL-UNNAMED",
        "--add-opens=java.base/java.util.concurrent=ALL-UNNAMED",
        "--add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED",
        "--add-opens=java.base/jdk.internal.ref=ALL-UNNAMED",
        "--add-opens=java.base/sun.nio.ch=ALL-UNNAMED",
        "--add-opens=java.base/sun.nio.cs=ALL-UNNAMED",
        "--add-opens=java.base/sun.security.action=ALL-UNNAMED",
        "--add-opens=java.base/sun.util.calendar=ALL-UNNAMED",
        "--add-opens=java.security.jgss/sun.security.krb5=ALL-UNNAMED",
        "-Djdk.reflect.useDirectMethodHandle=false",
        "-Dio.netty.tryReflectionSetAccessible=true",
        "--enable-native-access=ALL-UNNAMED"
    };

    /**
     * Returns the default JVM runtime options used by Spark.
     */
    public static String defaultModuleOptions() {
        return String.join(" ", DEFAULT_MODULE_OPTIONS);
    }

    /**
     * Returns the default JVM runtime option array used by Spark.
     */
    public static String[] defaultModuleOptionArray() {
        return DEFAULT_MODULE_OPTIONS;
    }
}
